package com.xbn.xbnmall.product.suanfa.s;

import org.apache.commons.lang.StringUtils;

import java.util.Stack;

/**
 * @author XBN
 * @date 2020/8/6 21:50
 * @email 78742541@qq.com
 */
public class Main {
    public static void main(String[] args) {
    Main main=new Main();
        System.out.println(main.largestRectangleArea(new int[]{1}));
    }
    public int largestRectangleArea(int[] heights) {
        Stack<Integer> stack=new Stack<>();
        int max=0;
        for (int i = 0; i < heights.length; i++) {


                    if(heights[i]==0)
                    {
                        stack.clear();
                    }
                    else if(!stack.isEmpty()&&heights[i]<stack.peek()){
                        for (int j = stack.size()-1; j >=0; j--) {
                            if(stack.get(j)>heights[i])
                            {
                                stack.set(j,heights[i]);
                            }
                        }
                    }
            stack.push(heights[i]);
            for (int j = stack.size()-1,k=1; j >=0 ; j--) {
                if(stack.get(j)*k>max)
                {
                    max=stack.get(j)*k;
                }
                k++;
            }
            }
        return max;
    }
}
